﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace SharePoint2010Poll
{
    [ToolboxItemAttribute(false)]
    public class PollWebPart : WebPart
    {
        #region Web Part Properties

        [WebBrowsable(false),
        Personalizable(PersonalizationScope.Shared),]
        public PollStates PollState { get; set; }

        #endregion

        protected override void CreateChildControls()
        {
            if (this.WebPartManager.DisplayMode.AllowPageDesign)
            {               
                    ManagePoll managePoll = (ManagePoll)Page.LoadControl("~/_controltemplates/SharePointPoll/ManagePoll.ascx");
                    this.Controls.Add(managePoll); 
            }
            else
            {
                if (this.PollState == PollStates.PollAdded)
                {
                    // Poll not configured, show nothing
                    this.Controls.Add(new LiteralControl("This poll is not yet open for responses."));
                }
                else
                {                  
                    ShowPoll showPoll = (ShowPoll)Page.LoadControl("~/_controltemplates/SharePointPoll/ShowPoll.ascx");
                    this.Controls.Add(showPoll);
                }
            }
        }
    }
}
